using HMCollada.Core;
using System.Collections.ObjectModel;
using HMCollada.Physics;
using System.Xml;

namespace HMCollada.Physics {
    internal struct HMColladaConvexMesh : HMColladaGeometryType {
        private Collection<HMColladaSource> source;
        private HMColladaVertices vertices;
        private Collection<HMColladaPolygons> polygons;
        private Collection<HMColladaPolylist> polylist;
        private Collection<HMColladaTriangles> triangles;

        internal string convex_hull_of;
        public Collection<HMColladaSource> Source { get { return source; } set { source = value; } }
        public HMColladaVertices Vertices { get { return vertices; } set { vertices = value; } }
        public Collection<HMColladaPolygons> Polygons { get { return polygons; } set { polygons = value; } }
        public Collection<HMColladaPolylist> Polylist { get { return polylist; } set { polylist = value; } }
        public Collection<HMColladaTriangles> Triangles { get { return triangles; } set { triangles = value; } }
    }
}

namespace HMCollada {
    internal partial class HMColladaLoader {
        private static HMColladaConvexMesh LoadConvexMesh() {
            HMColladaConvexMesh newConvexMesh = new HMColladaConvexMesh();
            newConvexMesh.convex_hull_of = colladaReader.GetAttribute("convex_hull_of");

            newConvexMesh.Source = new Collection<HMColladaSource>();
            newConvexMesh.Polygons = new Collection<HMColladaPolygons>();
            newConvexMesh.Triangles = new Collection<HMColladaTriangles>();

            if (!colladaReader.IsEmptyElement) colladaReader.Read();
            do {
                if (colladaReader.NodeType != XmlNodeType.EndElement) {
                    switch (colladaReader.Name) {
                        case "source": newConvexMesh.Source.Add(LoadSource()); break;
                        case "vertices": newConvexMesh.Vertices = LoadVertices(); break;
                        case "polygons": newConvexMesh.Polygons.Add(LoadPolygons()); break;
                        case "triangles": newConvexMesh.Triangles.Add(LoadTriangles()); break;
                    }
                }

                if (!colladaReader.IsEmptyElement) colladaReader.Read();
            } while (colladaReader.Name != "convex_mesh");

            if (colladaReader.IsEmptyElement) colladaReader.Read();
            return newConvexMesh;
        }
    }
}